package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.UserDao;
import com.foreknow.elm.dao.impl.UserDaoImpl;
import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.util.DBUtil;

public class UserServiceImpl  implements UserService {

    @Override
    public User getUserByIdByPass(String userId, String password) {
        UserDao userDao = new UserDaoImpl();
        User user=null;
        try {
            user = userDao.getUserByIdByPass(userId,password);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(); // 关闭Connection
        }

        return user;
    }

    @Override
    public int getUserById(String userId) {
        UserDao userDao = new UserDaoImpl();
       int user=0;
        try {
            user = userDao.getUserById(userId);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(); // 关闭Connection
        }
        return user;
    }

    @Override
    public int saveUser(String userId, String password, String userName, Integer userSex) {
        UserDao userDao = new UserDaoImpl();
        int add=0;
        try {
            add = userDao.saveUser(userId,password,userName,userSex);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(); // 关闭Connection
        }

        return add;
    }
}
